package com.quotes.charts;

import java.awt.Color;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.*;
import com.quotes.datamodell.*;
import com.quotes.datamodell.TimeSeries;
import com.quotes.dates.*;
import com.quotes.indicators.*;

public class MomentumChart extends LineChart
{
	private static final long serialVersionUID = 1L;
	private MomentumIndicator indicator = null;
	
	public MomentumChart(Quotes quotes, TimeRange range, int ticks) {
		super(quotes, range);
		indicator = new MomentumIndicator(quotes, ticks);
		
		this.createChart(quotes);
		logger.debug("MomentumChart created!");
	}
	
	protected XYDataset createXyDataset(Quotes product) {
		TimeSeriesCollection data = new TimeSeriesCollection();

		TimeSeries momentum = indicator.getMomentum().extract(range);
    	data.addSeries(momentum.convertToChartTimeSeries("Momentum"));
    	
		return data;
	}
	
	@Override
	protected XYPlot manipulatePlot(XYPlot plot) {
		XYItemRenderer renderer = plot.getRenderer();
		renderer.setSeriesPaint(0, Color.black);
		
		addVerticalMarker(plot, 0, Color.black);
		TimeSeries momentum = indicator.getMomentum().extract(range);
		
		for (TimeRange range : momentum.getPositiveRanges()) {
			addHorizontalMarker(plot, range, org.jfree.chart.ChartColor.LIGHT_GREEN);
		}

		for (TimeRange range : momentum.getNegativeRanges()) {
			addHorizontalMarker(plot, range, org.jfree.chart.ChartColor.LIGHT_RED);
		}
		
		return plot;
	}
}
